package com.xw.screen.capture.entity;

import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author ：xiongwei
 * @date ：Created in 2020/11/23 0:40
 */
public class MultipartFileImpl implements MultipartFile {

    private String fileName;
    private ByteArrayInputStream inputStream;

    public MultipartFileImpl(String fileName,ByteArrayInputStream inputStream){
        this.fileName = fileName;
        this.inputStream = inputStream;
    }

    @Override
    public String getName() {
        return fileName;
    }

    @Override
    public String getOriginalFilename() {
        return fileName;
    }

    @Override
    public String getContentType() {
        return null;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public long getSize() {
        try {
            return getBytes().length;
        } catch (IOException e) {
        }
        return 0L;
    }

    @Override
    public byte[] getBytes() throws IOException {
        byte[] b = new byte[1024 * 1024];
        inputStream.read(b);
        return b;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        return inputStream;
    }

    @Override
    public void transferTo(File file) throws IOException, IllegalStateException {

    }
}
